"use strict";
var __importDefault = (this && this.__importDefault) || function (mod) {
    return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
const GameRoom_1 = require("./room/GameRoom");
const colyseus_1 = require("colyseus");
const express_1 = __importDefault(require("express"));
const http_1 = require("http");
const port = Number(process.env.port) || 2567;
const app = express_1.default();
app.use(express_1.default.json());
// 初始化服务器
const gameServer = new colyseus_1.Server({
    server: http_1.createServer(app),
    // ws连接前的校验
    verifyClient: function (info, next) {
        next(true);
    },
    // 当通过多个进程/机器扩展Colyseus时，需要提供一个状态服务器
    // presence: new RedisPresence(),
});
// Define a new room handler.
// @ts-ignore
gameServer.define("game", GameRoom_1.GameRoom, {})
    .on("create", (room) => console.log("room created:", room.roomId))
    .on("dispose", (room) => console.log("room disposed:", room.roomId))
    .on("join", (room, client) => console.log(client.id, "joined", room.roomId))
    .on("leave", (room, client) => console.log(client.id, "left", room.roomId));
// Listen on port
gameServer.listen(port).then(r => console.log('server is on port ', port));
// Make sure to never call the `simulateLatency()` method in production.
if (process.env.NODE_ENV !== "production") {
    // simulate 200ms latency between server and client.
    gameServer.simulateLatency(200);
}
